/*
 *  $Id: Wound.cs 1004 2010-05-03 11:50:53Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Affects {
    /// <summary>
    /// Эффект: рана
    /// Параметры: значение (сила раны)
    /// В конце хода наносит игроку или существу урон, равный силе раны.
    /// </summary>
    public class Wound: FlagAffect {
        public readonly int Value;

        public Wound(int value) {
            Value = value;
        }

        public override string Id {
            get { return "wound"; }
        }
        public override string NameText {
            get { return Name.GetText(Value); }
        }
        public override ElementType Element {
            get { return ElementType.Neutral; }
        }

        public override string DescriptionText {
            get { return Description.GetText(Value); }
        }

        public override int BaseWeight {
            get { return Value * -30; }
        }

    	public override AffectIcon Icon {
            get { return AffectIcon.Wound; }
        }

        public override Affect Clone() {
            return new Wound(Value);
        }

        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.OnEndOffencePhase += DoWound;
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.OnEndOffencePhase -= DoWound;
        }

        private void DoWound() {
            if (Owner.HasFlag<Wound>()) Owner.DamageBy(NewDamage(DamageType.Wound, Value));
        }

        public static void SetOnDamage1(AbstractObject target, DamageInfo damage) {
            Creature attacker;
            if (MeleeDamageInfo.TryGetAttacker(damage, out attacker)) attacker.AddAffect(new Wound(1));
        }
    }

    /// <summary>
    /// Нанесение раны
    /// Параметры: сила раны
    /// Существо при ударе наносит своей цели рану указанной силы.
    /// </summary>
    public class WoundAttack: Affect {
        public readonly int Value;

        public WoundAttack(int value) {
            Value = value;
        }

        public override string Id {
            get { return "wound.attack"; }
        }
        public override string NameText {
            get { return Name.GetText(Value); }
        }

        public override ElementType Element {
            get { return ElementType.Neutral; }
        }

        public override int BaseWeight {
            get { return Value * 30; }
        }

        public override AffectIcon Icon {
            get { return AffectIcon.WoundAttack; }
        }

        public override Affect Clone() {
            return new WoundAttack(Value);
        }
 
        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.OnHit += DoHit;
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.OnHit -= DoHit;
        }

        private void DoHit(Creature hitter, AbstractObject target, int damage) {
            if (target is Creature) target.AddAffect(new Wound(Value));
        }
    }
}